import http from "@/http";

// 秒杀活动列表
export const getFlashList = (params: IUserListParams): RES<any> =>
  http.get("/flash/list", { params }); //根据活动名称分页查询

export const addActivity = (params: AddActivity): RES<number> =>
  http.post("/flash/create", params); //添加活动

export const SwitchActivity = (id: number, status: number): RES<number> =>
  http.post(`/flash/update/status/${id}?status=${status}`);

export const getActivityById = (id: number): RES<number> =>
  http.get(`/flash/${id}`); //获取活动详情

export const delActivity = (id: number): RES<number> =>
  http.post(`/flash/delete/${id}`); //删除活动

export const getFlashSessionSelectList = (id: number): RES<SelectSession> =>
  http.get(`/flashSession/selectList?flashPromotionId=${id}`); //获取全部可选场次及其数量(设置商品)

export const getFlashSessionList = (): RES<TimeListModel> =>
  http.get("/flashSession/list"); //获取全部场次（秒杀时间段列表）

export const delFlashSessionList = (id: number): RES<number> =>
  http.post(`/flashSession/delete/${id}`); //秒杀活动设置商品的删除按钮

export const getFlashSessionById = (id: number): RES<TimeListModel> =>
  http.get(`/flashSession/${id}`); //根据ID获取场次详情

export const FlashSessionUpdate = (params: TimeListModel): RES<number> =>
  http.post(`/flashSession/update/${params.id}`, params); //修改场次

export const addFlashSessionCreate = (params: TimeListModel): RES<number> =>
  http.post(`/flashSession/create`, params); //添加场次

export const changeActivity = (params: AddActivity): RES<number> =>
  http.post(`/flash/update/${params.id}`, params); //编辑活动

export const SwitchFlashSession = (id: number, status: number): RES<number> =>
  http.post(`/flashSession/update/status/${id}?status=${status}`); //控制是否启用(秒杀时间段列表)

//秒杀活动列表（商品列表）
export const getFlashProductRelationList = (
  flashPromotionId: number,
  flashPromotionSessionId: number,
  params: CouponListParams
): RES<FlashProductRelationList> =>
  http.get(
    `/flashProductRelation/list?flashPromotionId=${flashPromotionId}&flashPromotionSessionId=${flashPromotionSessionId}&pageNum=${params.pageNum}&pageSize=${params.pageSize}`
  ); //请求商品列表

export const getFlashProductRelationById = (
  id: number
): RES<FlashProductRelationList> => http.get(`/flashProductRelation/${id}`); //根据ID拿到编辑要渲染的数据

export const addFlashProductRelationCreate = (
  relationList: EditFlashProductRelation[]
): RES<number> => http.post(`/flashProductRelation/create`, relationList); //添加

export const getProductList = (params: ProductListParams): RES<any> =>
  http.get(
    `/product/list?keyword=${params.keyword}&pageNum=${params.pageNum}&pageSize=${params.pageSize}`
  ); //添加里面的数据

export const SearchProductList = (keyword: string): RES<IProductModel[]> =>
  http.get(`/product/simpleList?keyword=${keyword}`); //添加里面的搜索

export const editFlashProductRelation = (
  id: number,
  params: EditFlashProductRelation
): RES<number> => http.post(`/flashProductRelation/update/${id}`, params); //编辑

export const delFlashProductRelation = (id: number): RES<number> =>
  http.post(`/flashProductRelation/delete/${id}`); //删除关联
// 优惠券列表
export const getCouponList = (params: CouponListParams): RES<CouponListModel> =>
  http.get("/coupon/list", { params }); //根据优惠券名称和类型分页获取优惠券列表

export const delCoupon = (id: number): RES<number> =>
  http.post(`/coupon/delete/${id}`); //删除优惠券

export const getCouponHistoryList = (
  params: CouponHistoryListParams,
  couponId: number
): RES<CouponHistoryListModel> =>
  http.get(
    `/couponHistory/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}&couponId=${couponId}`,
    { params }
  ); //根据优惠券id，使用状态，订单编号分页获取领取记录

export const addCoupon=(params:ConPonParams):RES<number>=>http.post('/coupon/create',params)//添加优惠券

export const getProductCategoryListWithChildren=():RES<ProductCategoryWithChildren[]>=>http.get('/productCategory/list/withChildren')//添加可使用商品为指定分类

export const getCouponById=(id:number):RES<ConPonParams>=>http.get(`/coupon/${id}`)   //获取单个优惠券的详细信息  
// 品牌推荐
export const getBrandListAll = (params: BrandListParams): RES<BrandListModel> =>
  http.get(
    `/home/brand/list?&pageNum=${params.pageNum}&pageSize=${params.pageSize}`,
    { params }
  );

export const SwitchRecommendStatus = (
  ids: number,
  Status: number
): RES<number> =>
  http.post(
    `/home/brand/update/recommendStatus?ids=${ids}&recommendStatus=${Status}`
  );

export const get = (params: IUserListParams): RES<BrandModel> =>
  http.get(
    `/brand/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`,
    { params }
  ); //YJL test (根据品牌名称分页获取品牌列表)(品牌管理)

//新品推荐
export const getNewProductList = (
  params: NewProductParams
): RES<NewProductModel> =>
  http.get(
    `/home/newProduct/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`,
    { params }
  );

//人气推荐
export const getRecommendProductList = (
  params: NewProductParams
): RES<NewProductModel> =>
  http.get(
    `/home/recommendProduct/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`,
    { params }
  );

//专题推荐
export const getRecommendSubjectList = (
  params: NewProductParams
): RES<NewProductModel> =>
  http.get(
    `/home/recommendSubject/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`,
    { params }
  );

//广告列表
export const getAdvertiseList = (
  params: AdvertiseParams
): RES<AdvertiseModel> =>
  http.get(
    `/home/advertise/list?pageNum=${params.pageNum}&pageSize=${params.pageSize}`
  );

// 修改专题推荐排序
export const homeSubjectUpdateSortApi = (
  params: UpdateSortModel
): RES<number> =>
  http.post(
    `/home/recommendSubject/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`
  );

// 修改人气推荐排序
export const HomeHotUpdateSortApi = (params: UpdateSortModel): RES<number> =>
  http.post(
    `/home/recommendProduct/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`
  );

// 修改新品推荐排序
export const HomeNewUpdateSortApi = (params: UpdateSortModel): RES<number> =>
  http.post(
    `/home/newProduct/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`
  );

//  修改品牌推荐排序
export const HomeBrandUpdateSortApi = (params: UpdateSortModel): RES<number> =>
  http.post(
    `/home/brand/update/sort/${params.id}?sort=${params.sort}&id=${params.id}`
  );

// 删除专题推荐
export const homeSubjectDeleteApi = (ids: number[]): RES<number> =>
  http.post(`/home/recommendSubject/delete?ids=${ids.join(",")}`);

// 删除人气推荐
export const HomeHotDeleteApi = (ids: number[]): RES<number> =>
  http.post(`/home/recommendProduct/delete?ids=${ids.join(",")}`);

// 删除新品推荐
export const HomeNewDeleteApi = (ids: number[]): RES<number> =>
  http.post(`/home/newProduct/delete?ids=${ids.join(",")}`);

// 删除品牌推荐
export const HomeBrandDeleteApi = (ids: number[]): RES<number> =>
  http.post(`/home/brand/delete?ids=${ids.join(",")}`);
